--[[
	Project:		TruRP
	Author:			Martin 'Ploo' Pucilowski
	File:			chat.lua
	Date:			02/2010
	Description:	Manages all chat and voice functions
--]]

--[[

OOC
// Global
\\ Local

IC
/a Advert
/w Whisper
   Talk
/y Yell
/r Radio (via the radio, with others on the same frequency)

x	(Voice) local IC
	Voice via the radio, with others on the same frequency

--]]



Comms = {  }
Comms = { 
	{ name = "whisper", prefix = "/w", range = 100 },
	{
		name = "talk",
		prefix = "",
		range = 200
	},
	{
		name = "yell",
		prefix = "/y",
		range = 300
	},
	{
		name = "advert",
		prefix = "/a",
		range = 0
	},
	{
		name = "ooc",
		prefix = "//",
		range = 0
	}
}

local function IsInRange( ply, ply2, range )
	range = Comms.Range[range]
	
	if ply:GetPos():Distance(ply2:GetPos()) <= range then
		return true
	end
	return false
end


function GM:PlayerSay( player, text, teamonly )
	-- The teamonly flag is the other way around.
	if teamonly then
		return PlayerSay( player, text )
	else
		return PlayerSayGroup( player, text )
	end	
end

function PlayerSay( player, text )	
	-- Check if it is a chat command
	if string.sub( text, 1, 1 ) == "/" then
		local command = string.sub( text, 2 )
		PlayerChatCommand( player, command )
		return false
	end
	
	
	
	
	return text .. " (LOCALCHAT)"
end

function PlayerSayGroup( player, text )
	return text .. " (TEAMCHAT)"
end

function GM:PlayerCanSeePlayersChat( strText, bTeamOnly, pListener, pSpeaker )
	print("can they see the chat?")

	prefix = string.Explode(" ", text)[1]
	print("ChatPrefix: " .. prefix )
end



function GM:PlayerCanHearPlayersVoice( pListener, pTalker )
	return true
	
	--return pListener.RadioFreq == pTalker.RadioFreq
end
